package com.zhang.modules.user.service.impl;

import com.zhang.modules.user.service.PasswordEncoder;
import org.springframework.data.redis.core.script.DigestUtils;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class Md5PasswordEncoder implements PasswordEncoder {

    /**
     * @param password password+salt
     */
    @Override
    public  String encode(String password) {
        return DigestUtils.sha1DigestAsHex(password);
    }

    @Override
    public  Boolean match(String originPassword, String encodedPassword) {
        return Objects.equals(encode(originPassword),encodedPassword);
    }
}
